package com.tanhua.server.controller;

import com.tanhua.server.service.SoundService;
import com.tanhua.server.vo.SoundVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/peachblossom")
public class SoundController {


    @Autowired
    private SoundService soundService;

    //语音上传
    @PostMapping
    public ResponseEntity<Void> soundUpload(@RequestParam(value = "soundFile", required = false) MultipartFile soundFile){

        try {
            Boolean bool = soundService.soundUpload(soundFile);
            if (bool){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }



    //查询语音
    @GetMapping
    public ResponseEntity<SoundVo> querySound(){

        try {
            SoundVo soundVo  =  soundService.querySound();
            if (soundVo != null){
                return ResponseEntity.ok(soundVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }


}
